package net.lab1024.smartadmin.module.business.drivecycleTab.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.module.business.drivecycleTab.dao.DrivingCycleTbDao;
import net.lab1024.smartadmin.module.business.drivecycleTab.domain.dto.DrivingCycleTbAddDTO;
import net.lab1024.smartadmin.module.business.drivecycleTab.domain.dto.DrivingCycleTbQueryDTO;
import net.lab1024.smartadmin.module.business.drivecycleTab.domain.dto.DrivingCycleTbUpdateDTO;
import net.lab1024.smartadmin.module.business.drivecycleTab.domain.entity.DrivingCycleTbEntity;
import net.lab1024.smartadmin.module.business.drivecycleTab.domain.vo.DrivingCycleTbExcelVO;
import net.lab1024.smartadmin.module.business.drivecycleTab.domain.vo.DrivingCycleTbVO;
import net.lab1024.smartadmin.util.SmartBeanUtil;
import net.lab1024.smartadmin.util.SmartPageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * [ 行驶工况特性曲线table数据 ]
 *
 * @author wuhq
 * @version 1.0
 * @company 汽车传动
 * @copyright (c)  汽车传动Inc. All rights reserved.
 * @date 2022-01-22 11:43:10
 * @since JDK1.8
 */
@Service
public class DrivingCycleTbService {

    @Autowired
    private DrivingCycleTbDao drivingCycleTbDao;

    /**
     * 根据id查询
     */
    public DrivingCycleTbEntity getById(Long id){
        return  drivingCycleTbDao.selectById(id);
    }

    /**
     * 分页查询
     * @author wuhq
     * @date 2022-01-22 11:43:10
     */
    public ResponseDTO<PageResultDTO<DrivingCycleTbVO>> queryByPage(DrivingCycleTbQueryDTO queryDTO) {
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        IPage<DrivingCycleTbVO> voList = drivingCycleTbDao.queryByPage(page, queryDTO);
        PageResultDTO<DrivingCycleTbVO> pageResultDTO = SmartPageUtil.convert2PageResult(voList);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * 添加
     * @author wuhq
     * @date 2022-01-22 11:43:10
     */
    public ResponseDTO<String> add(DrivingCycleTbAddDTO addDTO) {
        DrivingCycleTbEntity entity = SmartBeanUtil.copy(addDTO, DrivingCycleTbEntity.class);
        drivingCycleTbDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * 编辑
     * @author wuhq
     * @date 2022-01-22 11:43:10
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(DrivingCycleTbUpdateDTO updateDTO) {
        DrivingCycleTbEntity entity = SmartBeanUtil.copy(updateDTO, DrivingCycleTbEntity.class);
        drivingCycleTbDao.updateById(entity);
        return ResponseDTO.succ();
    }

    /**
     * 删除
     * @author wuhq
     * @date 2022-01-22 11:43:10
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        drivingCycleTbDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    /**
     * 查询全部导出对象
     * @author wuhq
     * @date 2022-01-22 11:43:10
     */
    public List<DrivingCycleTbExcelVO> queryAllExportData(DrivingCycleTbQueryDTO queryDTO) {
        return drivingCycleTbDao.queryAllExportData( queryDTO);
    }

    /**
     * 批量查询导出对象
     * @author wuhq
     * @date 2022-01-22 11:43:10
     */
    public List<DrivingCycleTbExcelVO> queryBatchExportData(List<Long> idList) {
        return drivingCycleTbDao.queryBatchExportData(idList);
    }

    public void delByDrivingCycleId(Long id) {
        LambdaQueryWrapper<DrivingCycleTbEntity> queryWrapper = new LambdaQueryWrapper<DrivingCycleTbEntity>();
        queryWrapper.eq(DrivingCycleTbEntity::getDrivingCycleId, id);
        drivingCycleTbDao.delete(queryWrapper);
    }

    public DrivingCycleTbEntity getByDrivingCycleId(Long drivingCycleId) {
        LambdaQueryWrapper<DrivingCycleTbEntity> queryWrapper = new LambdaQueryWrapper<DrivingCycleTbEntity>();
        queryWrapper.eq(DrivingCycleTbEntity::getDrivingCycleId, drivingCycleId);
        return drivingCycleTbDao.selectOne(queryWrapper);
    }
}
